import java.util.Random;


	class Sailor {
		
		private int posx;
		private int posy;
		private int finalposition; //1 = Boat, 2 = Water, 3 = Bar
		
		public Sailor(){
			posx = 0;
			posy = 0;
			finalposition = 0;
		}
		
		
		public int getPosx(){
			return this.posx;
		}
		
		public int getPosy(){
			return this.posy;
		}
		
		public int getFinalPosition(){
			return this.finalposition;
		}
		
		public void moveLeft(){
			this.posx = this.posx - 1;
		}
		
		public void moveRight(){
			this.posx = this.posx + 1;
		}
		
		public void moveForward(){
			this.posy = this.posy + 1;
		}
		
		public void moveBackward(){
			this.posy = this.posy - 1;
		}

		public boolean onDock(){
			return (this.posx <= 2.5 && this.posx >= -2.5 && this.posy <= 20 && this.posy >= 0);
		}
		
		public void takeStep(){
			if(this.onDock() == true){
			Random randomgenerator = new Random();
			int n = randomgenerator.nextInt(10);
			
			if(n == 0){
				moveLeft();
			}
			else if(n == 1){
				moveRight();
			}
			else if(n == 2){
				moveBackward();
			}
			
			else if(n >= 3 && n <= 9){
				moveForward();
			}
		}
		}
		
		public void setFinalPosition(){
			if(this.onDock() == false){
				if(this.posy < 0){
					this.finalposition = 3;
				}
				else if(this.posy > 20){
					this.finalposition = 1;
				}
				else if (this.posx > 2.5 || this.posx < -2.5){
					this.finalposition = 2;
				}
			}
		}
		
		public void update(){
			this.takeStep();
			this.setFinalPosition();
		}
		
		
}
